<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('公司近况') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('参股基金')" prop="dealId">
        <el-select v-model="queryParams.dealId" filterable clearable :placeholder="$t('请选择')">
          <el-option
            v-for="item in dealNameOptions"
            :key="item.id"
            :label="item.label"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('发生时间')" prop="occurrenceTime">
        <DatePicker v-model="dateRange" type="daterange" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['company:projectRecentDevel:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}</el-button>
      </el-col>
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          v-hasPermi="['company:projectRecentDevel:export']"-->
      <!--          type="warning"-->
      <!--          icon="el-icon-download"-->
      <!--          size="mini"-->
      <!--          @click="exportHandle"-->
      <!--        >{{ $t('导出') }}</el-button>-->
      <!--      </el-col>-->
    </el-row>

    <el-table v-loading="loading" :data="companyProjectRecentDevelList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('参股基金')" align="center" prop="dealName" show-overflow-tooltip min-width="200" />
      <el-table-column :label="$t('发生时间')" align="center" prop="occurrenceTime" show-overflow-tooltip min-width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.occurrenceTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('业务介绍')" align="center" prop="businessDescription" :formatter="businessDescriptionFormat" show-overflow-tooltip min-width="200" />
      <el-table-column :label="$t('公司主要发展和近期计划')" align="center" prop="recentDevel" :formatter="recentDevelFormat" show-overflow-tooltip min-width="200" />
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['company:projectRecentDevel:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}</el-button>
          <el-button
            v-hasPermi="['company:projectRecentDevel:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改间接项目-公司近况对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" :destroy-on-close="true" append-to-body>
      <companyProjectRecentDevelForm ref="companyProjectRecentDevelForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listCompanyProjectRecentDevel, delCompanyProjectRecentDevel, exportCompanyProjectRecentDevel } from '@/api/sass/jswt/projectRecentDevel/companyProjectRecentDevel'
import companyProjectRecentDevelForm from './companyProjectRecentDevelForm.vue'
import { lisDealName } from '@/api/bf/investGroup/bfInvestGroup'
export default {
  components: {
    companyProjectRecentDevelForm
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 间接项目-公司近况表格数据
      companyProjectRecentDevelList: [],
      // 参股基金下拉框
      dealNameOptions: [],
      // 发生时间
      dateRange: [],
      // 弹出层标题
      title: '公司近况',
      // 是否显示弹出层
      formOpen: false,
      // 查询参数
      queryParams: {
        companyId: this.$route.query.companyId,
        dealId: undefined,
        occurrenceTime: undefined,
        businessDescription: undefined,
        recentDevel: undefined,
        pageNum: 1,
        pageSize: 10
      },
      bfDealQueryParams: {
        indirectDealId: this.companyId || this.$route.query.companyId,
        source: 'BF_PORTFOLIO'
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
    // 获取所有关联项目
    lisDealName(this.bfDealQueryParams).then(response => {
      this.dealNameOptions = response.rows
    })
  },
  methods: {
    /** 查询间接项目-公司近况列表 */
    getList() {
      this.loading = true
      listCompanyProjectRecentDevel(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.companyProjectRecentDevelList = response.rows
        this.total = response.total
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    businessDescriptionFormat(row) {
      const replace = row.businessDescription.replace(/<[^>]+>/g, '')
      return replace.replace(/&[^;]+;/g, '')
    },
    recentDevelFormat(row) {
      const replace = row.recentDevel.replace(/<[^>]+>/g, '')
      return replace.replace(/&[^;]+;/g, '')
    },

    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        companyId: this.$route.query.companyId,
        dealId: this.$route.query.dealId,
        occurrenceTime: undefined,
        businessDescription: undefined,
        recentDevel: undefined,
        remark: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm('queryForm')
      this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
      this.formOpen = true
      this.$nextTick(() => {
        this.$refs.companyProjectRecentDevelForm.init(null)
      })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
      this.formOpen = true
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.companyProjectRecentDevelForm.init(row)
      })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(() => {
        return delCompanyProjectRecentDevel(row.id)
      }).then(() => {
        this.getList()
        this.msgSuccess(this.$t('删除成功'))
      }).catch(() => {
        this.loading = false
      })
    },
    /** 导出按钮操作 */
    exportHandle() {
      const queryParams = this.queryParams
      this.$confirm(this.$t('是否确认导出数据项?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(() => {
        return exportCompanyProjectRecentDevel(queryParams)
      }).then(response => {
        this.download(response.msg)
      }).catch(() => {
      })
    }
  }
}
</script>
